/**
 *****************************************************************************
 * @file    drv_flash_api.h
 *
 * @brief    -
 *
 * Copyright (C) RealMega 2019-2020
 *
 *****************************************************************************
*/


#define FLASH_SECTOR_SIZE       4096
#define FLASH_SIZE     (256*1024)

enum DRV_FLASH_ERASE_UNIT_TYPE
{
    FLASH_ERASE_SECTOR          = 0,
    FLASH_ERASE_BLOCK32         = 1,
    FLASH_ERASE_BLOCK64         = 2,
    FLASH_ERASE_ALL_CHIP        = 3,

    FLASH_ERASE_UNIT_RESERVED
};

/**
 **************************************************************************************
 * @brief  This function is used to erase flash, it can erase a sector, a 32K block, a 64K 
 *              block or all chip at a time.
 *
 * @param  unit_type, see @enum DRV_FLASH_ERASE_UNIT_TYPE.
 * 
 * @param  start_addr, start address of the block to be erased, and it should be aligned
 *              to the block size depends on parameter unit_type, except FLASH_ERASE_ALL_CHIP
 *              used.
 *
 * @return see enum COMMON_ERR_CODES.
 *************************************************************************************
 */
uint8_t drv_flash_unit_erase(uint8_t unit_type, uint32_t start_addr);

/**
 **************************************************************************************
 * @brief  This function is used to write data into flash.
 *
 * @param  start_addr, the start address that data to be written, and it can be any 
 *                  address in the flash space.
 *
 * @param  data, a poniter to the data to be written.
 * 
 * @param  length, the legth of the data to be written.
 *
 * @return see enum COMMON_ERR_CODES.
 *************************************************************************************
 */
uint8_t drv_flash_write(uint32_t start_addr, const uint8_t* data, uint32_t length);


